//
//  HOTCostPopupHandler.m
//  Genpara
//
//  Created by zhang chunhui on 14/11/13.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#define HOTCostPopupStyleMsg1 @"プロフィール閲覧に\n10現使用します。\nよろしいですか?"
#define HOTCostPopupStyleMsg2 @"メッセージ送信に\n20現使用します。\nよろしいですか?"
#define HOTCostPopupStyleMsg3 @"%@を見るのに\n5現使用します。\nよろしいですか?"
#define HOTCostPopupStyleMsg4 @"発注書発行に\n500現使用します。\nよろしいですか?"

#import "HOTCostPopupHandler.h"
#import "HOTConfig.h"

@interface HOTCostPopupHandler()

@property(nonatomic,copy)void(^cancelBlock)(void);
@property(nonatomic,copy)void(^okBlock)(void);

@end

@implementation HOTCostPopupHandler

static HOTCostPopupHandler *handler;
+(instancetype)costPopupHandler {
    
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        handler = [[[self class] alloc] init];
    });
    
    return handler;
}


-(void)showWithPopupStyle:(HOTCostPopupStyle)style
                 userInfo:(NSDictionary *)userInfo
                   cancel:(void(^)(void))cancelBlock
                  confirm:(void(^)(void))confirmBlock {
    
    self.cancelBlock = cancelBlock;
    self.okBlock = confirmBlock;
    
        
    NSString *msg = @"";
    switch (style) {
        case HOTCostPopupStyle1:
            
            msg = HOTCostPopupStyleMsg1;
            break;
        case HOTCostPopupStyle2:
            
            msg = HOTCostPopupStyleMsg2;
            break;
        case HOTCostPopupStyle3:
            
            msg = [NSString stringWithFormat:HOTCostPopupStyleMsg3, [HOTUtils getString:[userInfo objectForKey:@"title"]]] ;
            break;
        case HOTCostPopupStyle4:
            
            msg = HOTCostPopupStyleMsg4;
            break;
            
        default:
            break;
    }
    
    ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE message:msg delegate:self cancelButtonTitle:ALERT_BTN_CANCEL otherButtonTitle:ALERT_BTN_OK];
    
    [popupView showInWindow];
    
}


-(void)popupView:(ZZZPopupView *)popupView buttonKind:(ZZZPopupViewBtnKind)btnKind {
    
    
    if (btnKind == ZZZPopupViewConfirmBtnKind) {
        
        if (self.okBlock) {
            
            self.okBlock();
        }
        
    } else {
        
        if (self.cancelBlock) {
            self.cancelBlock();
        }
    }
}

@end
